package controlador;

import java.io.Serializable;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.util.ArrayList;
import java.util.List;

import dao.ClienteDAO;
import dominio.Cliente;
import dto.ClienteTO;
import remoto.IGestionClientes;

public class GestionClientes extends UnicastRemoteObject implements IGestionClientes, Serializable {
	private static final long serialVersionUID = 1L;

	public GestionClientes() throws RemoteException {
		super();
	}

	@Override
	public int guardarCliente(ClienteTO cliente) throws RemoteException {
		return ClienteDAO.getInstance().guardarCliente(Cliente.fromDTO(cliente));
	}

	@Override
	public ClienteTO buscarCliente(String cuil) throws RemoteException {
		Cliente c = ClienteDAO.getInstance().buscarCliente(cuil);
		if (c != null)
			return c.getDTO();
		return null;
	}

	@Override
	public List<ClienteTO> listarClientes() throws RemoteException {
		List<ClienteTO> lista = new ArrayList<ClienteTO>();
		List<Cliente> clientes = ClienteDAO.getInstance().listarClientes();
		for (Cliente c : clientes)
			lista.add(c.getDTO());
		return lista;
	}
}